﻿#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution
{
public:
    // 49. 字母异位词分组
    vector<vector<string>> groupAnagrams(vector<string>& strs)
    {
        vector<vector<string>> ret;
        unordered_map<string, vector<string>> hash;
        for (auto& s : strs)
        {
            string tmp = s;
            sort(tmp.begin(), tmp.end());
            hash[tmp].push_back(s);
        }
        for (auto str : hash)
            ret.push_back(str.second);
        return ret;
    }
};

int main()
{
    vector<string> v{ "eat", "tea", "tan", "ate", "nat", "bat" };
    Solution().groupAnagrams(v);

    return 0;
}